package ph.edu.upd.eee.upcatarchivesearch;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by smartwire on 10/7/2014.
 */
public class SearchResultsArrayAdapter extends ArrayAdapter<SearchResult> {
    private Context context;
    private ArrayList <SearchResult> resultSet;

    public SearchResultsArrayAdapter(Context c, ArrayList<SearchResult> resultSet) {
        super(c, R.layout.listitem_result, resultSet);

        this.context = c;
        this.resultSet = resultSet;
    }

    public View getView(int pos, View convertView, ViewGroup parent) {
        View rowView;
        TextView txtID, txtName, txtSN, txtCourse, txtCampus;

        SearchResult result;

        if(convertView == null) {
            rowView = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listitem_result, parent, false);
        }
        else {
            rowView = convertView;
        }

        txtID = (TextView) rowView.findViewById(R.id.txt_listitemresult_id);
        txtName = (TextView) rowView.findViewById(R.id.txt_listitemresult_name);
        txtSN = (TextView) rowView.findViewById(R.id.txt_listitemresult_sn);
        txtCourse = (TextView) rowView.findViewById(R.id.txt_listitemresult_course);
        txtCampus = (TextView) rowView.findViewById(R.id.txt_listitemresult_campus);

        result = resultSet.get(pos);

        txtID.setText((pos + 1) + "");
        txtName.setText(result.getName());
        txtSN.setText(result.getSN());
        txtCourse.setText(result.getCourse());
        txtCampus.setText(result.getCampus());

        return rowView;
    }
}
